<?php
require_once 'SpotLight/configs/dbConfig.php';

/**
 * Load actions and interceptors.
 * 
 * @version since begin.
 * @author asmhack
 * @license GPL
 * @link http://www.spotlight.cv.ua/
 * @copyright Serhiy Zaporozhets'
 */
abstract class Loader {
	
	const CLASS_EXTENSION='.class.php';
	
	public static $confs=array(
	   'ConfigReader'=>'SpotLight/core/configurator',
	   'ActionColl'=>'SpotLight/core/configurator/collector',
	   'FlowColl'=>'SpotLight/core/configurator/collector',
	   'DispatcherColl'=>'SpotLight/core/configurator/collector',
	   'InterceptorColl'=>'SpotLight/core/configurator/collector',
	   'PackageColl'=>'SpotLight/core/configurator/collector',
	   'ResultColl'=>'SpotLight/core/configurator/collector',
	   'TagLibColl'=>'SpotLight/core/configurator/collector',
	   'Connection'=>'SpotLight/core/db',
	   'DBDriver'=>'SpotLight/core/db',
	   'MySQLDriver'=>'SpotLight/core/db/drivers',
	   'WorkFlow'=>'SpotLight/core/debug',
	   'ErrorHandler'=>'SpotLight/core/debug',
	   'Benchmark'=>'SpotLight/core/debug',
	   'Error'=>'SpotLight/core/errors',
	   'Errors'=>'SpotLight/core/errors',
	   'ErrorsCollector'=>'SpotLight/core/errors',
	   'Action'=>'SpotLight/core/events',
	   'Actionable'=>'SpotLight/core/events',
	   'Interceptor'=>'SpotLight/core/events',
	   'Serviceable'=>'SpotLight/core/events',
	   'Templatable'=>'SpotLight/core/events',
	   'ActionInvokeException'=>'SpotLight/core/exceptions',
	   'ConfigException'=>'SpotLight/core/exceptions',
	   'DBException'=>'SpotLight/core/exceptions',
	   'FilterInvokeException'=>'SpotLight/core/exceptions',
	   'LocalizatorException'=>'SpotLight/core/exceptions',
	   'FileInlcudeException'=>'SpotLight/core/exceptions',
	   'ValidatorInvokeException'=>'SpotLight/core/exceptions',
	   'Request'=>'SpotLight/core/HTTP',
	   'Response'=>'SpotLight/core/HTTP',
	   'Session'=>'SpotLight/core/HTTP',
	   //'Router'=>'SpotLight/core/HTTP',
	   'DefaultRequestDispatcher'=>'SpotLight/core/HTTP/dispatcher',
	   'HRURequestDispatcher'=>'SpotLight/core/HTTP/dispatcher',
	   'RequestDispatcher'=>'SpotLight/core/HTTP/dispatcher',
	   'Localizable'=>'SpotLight/core/i18n',
	   'Localizator'=>'SpotLight/core/i18n',
	   'Loader'=>'SpotLight/core/system',
	   'AnnotationInvoker'=>'SpotLight/core/system',
	   'Annotation'=>'SpotLight/core/system/annotations',
	   'ValidateAnnotation'=>'SpotLight/core/system/annotations',
	   //'TmplRegExpAnnotation'=>'SpotLight/core/system/annotations',
	   'Log4php'=>'SpotLight/core/log4php',
	   'Templater'=>'SpotLight/core/templater',
	   'BaseTag'=>'SpotLight/core/templater/tags',
	   'ExceptionPage'=>'SpotLight/core/view',
	
	   'SpotLight'=>'SpotLight/core',
	   #helpers:
	   'html'=>'SpotLight/helpers',
	   'url'=>'SpotLight/helpers',
	   
	   );
	
	public static function resolvePackByClassName($fullName) { 
	   
	   if (key_exists ( $fullName, self::$confs ))
			return self::$confs [$fullName];
	   else
			die ( $fullName . ' not found' );
	}
	
	public static function load($fullName) {
	   
	   $pack=self::resolvePackByClassName($fullName);
	   
	   $f=$pack.'/'.$fullName.self::CLASS_EXTENSION;
	   if(file_exists($f))
	      require_once $f;
	   else 
	   	throw new Exception($f.' can\'t found'); 
	}

	

	
}

function __autoload($class) {
	try {
		Loader::load($class);
	} catch (Exception $exception) {
		echo $exception->getMessage().'<hr/>';
		echo '<pre>'.$exception->getTraceAsString().'</pre>';
		die('Could not autoload ' . $class);
	}
}
ErrorHandler::setHandler ();

?>